package lx13;

import java.lang.reflect.Field;
import java.util.Arrays;

public class Get_Field {
    public static void main(String[] args) throws IllegalAccessException {
        //反射获取成员变量

        //1.获取到class字节码文件对象
        Class cls = sstu.class;

        //获取成员变量方法
        Field[] fs = cls.getDeclaredFields();
        //获取权限修饰符
        int f = fs[0].getModifiers();
        Class<?> t = fs[0].getType();
        System.out.println(Arrays.toString(fs) + "  " + f + "  " + t);

        //fs[0] --> name成员变量
        sstu tu = new sstu();
        System.out.println(tu);
        fs[0].setAccessible(true);
        System.out.println(fs[0].get(tu));

        fs[0].set(tu,"0dOo");//将tu这个对象的name设置为 0dOo
        System.out.println(tu);
    }
}
